<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "UserCategory".
 */
class UserCategory extends ActiveRecord {

    // @name 熟练度
    const TypeCategory = 0;
    const TypeModel = 1;
    const TypeStyle = 2;
    public static $typeSelector = [
        self::TypeCategory => ['title' => '擅长类目', 'status' => 'blue'],
        self::TypeModel => ['title' => '擅长类型', 'status' => 'red'],
        self::TypeStyle => ['title' => '擅长风格', 'status' => 'purple'],
    ];

    // only define rules for those attributes that
    // will receive user inputs.
    public function rules()
    {
        return [
            [['user_id', 'type', 'category_id'], 'required'],
            [['user_id', 'type'], 'integer'],
            [['category_id'], 'string', 'max' => 16],
        ];
    }
    /**
     * @name 字段名称
     * @return array
     */
    public function attributeLabels()
    {
        return [
            'user_id' => '用户',
            'type' => '类型',
            'category_id' => '类目',
        ];
    }

    /**
     * @name 获取user信息
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(User::className(), ['id' => 'user_id']);
    }
}